package com.hbt.user_consumer.controller;

import com.hbt.api.entity.CommonResult;
import com.hbt.api.entity.User;
import com.hbt.user_consumer.service.UserServiceFeign;
import com.hbt.user_consumer.service.UserUploadServiceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("user_consumer")
public class UserConsumerController {
    @Autowired
    UserServiceFeign userServiceFeign;
    @Autowired
    UserUploadServiceFeign userUploadServiceFeign;
    @Autowired
    RedisTemplate redisTemplate;
    @RequestMapping("test")
    public String test(){
        System.out.println("enter UserConsumerController test");
        userUploadServiceFeign.test();
        return "test success";
    }

    @PostMapping("uploadAvatar")
    public CommonResult uploadAvatar(MultipartFile file, @RequestParam("token") String token){
        System.out.println("enter user_conusermer uploadAvatar");
//        MulFileAndToken mulFileAndToken = new MulFileAndToken();
//        mulFileAndToken.setFile(file);
//        mulFileAndToken.setToken(token);
        if (file == null){
            System.out.println(" user_conusermer file == null");
        }else {
            System.out.println("user_conusermer file name = "+file.getOriginalFilename());
        }
        return userServiceFeign.uploadAvatar(file, token);
//        return null;
    }


    @PostMapping("getUserByToken")
    public CommonResult getUserByToken(String token){
        return userServiceFeign.getUserByToken(token);
//        return null;
    }

    @RequestMapping("dologin")
    public CommonResult dologin(User user) {
        System.out.println("进入 user consumer controller dologin");
        System.out.println("user:"+user);

        return userServiceFeign.dologin(user);
    }
}
